﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SD.IDAL;
using SD.Entities;
using System.Data.SqlClient;
using System.Data;

namespace SD.DAL
{
    public class DirectorateDAO : BaseDAO, IDirectorateDAO
    {

        #region IDirectorateDAO Members

        /// <summary>
        /// Get list of Directorate
        /// </summary>
        /// <param name="filterExpression">filterExpression parammeter</param>
        /// <param name="includeInactive">includeInactive parammeter</param>
        /// <returns>Return list of Directorate</returns>
        public List<Directorate> GetAll(string filterExpression, bool includeInactive)
        {
            // Create a command object
            SqlCommand comm = CreateCommand();
            // Call command by store
            comm.CommandText = "DirectorateGetAll";
            // Add parammeter to store procedure
            comm.Parameters.AddWithValue("@filterExpression", filterExpression);
            comm.Parameters.AddWithValue("@includeInactive", includeInactive);

            // Create a data table
            DataTable dt = ExecuteSelectCommand(comm);
            // Get list of directorate
            List<Directorate> list = new List<Directorate>();
            Directorate d = null;

            // Browse the list and add to table
            foreach (DataRow row in dt.Rows)
            {
                d = new Directorate();
                d.DirectorateId = row["DirectorateID"].ToString();
                d.Name = row["Name"].ToString();
                d.Address = row["AddressID"] == DBNull.Value ? null : new AddressDAO().GetById(row["AddressID"].ToString());
                d.Contact = row["ContactID"] == DBNull.Value ? null : new ContactDAO().GetById(row["ContactID"].ToString());                
                d.IsActive = bool.Parse(row["IsActive"].ToString());
                list.Add(d);
            }

            // Return the list
            return list;
        }
        /// <summary>
        /// Get list of Directorate
        /// </summary>
        /// <param name="filterExpression">filterExpression parammeter</param>
        /// <param name="includeInactive">includeInactive parammeter</param>
        /// <returns>Return list of Directorate</returns>
        public List<Directorate> GetAllFilter(bool includeInactive)
        {
            // Create a command object
            SqlCommand comm = CreateCommand();
            // Call command by store
            comm.CommandText = "DirectorateGetAllFilter";
            // Add parammeter to store procedure        
            comm.Parameters.AddWithValue("@includeInactive", includeInactive);
            // Create a data table
            DataTable dt = ExecuteSelectCommand(comm);
            // Get list of directorate
            List<Directorate> list = new List<Directorate>();
            Directorate d = null;

            // Browse the list and add to table
            foreach (DataRow row in dt.Rows)
            {
                d = new Directorate();
                d.DirectorateId = row["DirectorateID"].ToString();
                d.Name = row["Name"].ToString();
                d.Address = row["AddressID"] == DBNull.Value ? null : new AddressDAO().GetById(row["AddressID"].ToString());
                d.Contact = row["ContactID"] == DBNull.Value ? null : new ContactDAO().GetById(row["ContactID"].ToString());
                d.IsActive = bool.Parse(row["IsActive"].ToString());
                list.Add(d);
            }

            // Return the list
            return list;
        }

        /// <summary>
        /// Get list of Directorate by ID
        /// </summary>
        /// <param name="orgId">orgId parammeter</param>
        /// <returns>Return list of Diretorate by ID</returns>
        public List<Directorate> GetByOrgId(string orgId)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Get Directorate by ID
        /// </summary>
        /// <param name="directorateId">directorateId parammeter</param>
        /// <returns>Return Directorate</returns>
        public Directorate GetById(string directorateId)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Insert directorate into system
        /// </summary>
        /// <param name="directorate">directorate parammeter</param>
        /// <returns>Return result of insert. If insert success return true, else return false</returns>
        public bool Insert(Directorate directorate)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Update directorate into system
        /// </summary>
        /// <param name="directorate">directorate parammeter</param>
        /// <returns>Return the result of update. If update success return true, else return false</returns>
        public bool Update(Directorate directorate)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Delete directorate from system
        /// </summary>
        /// <param name="directorateId">directorateId parammeter</param>
        /// <returns>Return the result of delete. If delete success return true, else return false</returns>
        public bool Delete(string directorateId)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
